package com.codegenerate.demo.dto;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codegenerate.demo.config.R;
import com.codegenerate.demo.entity.SysTemplate;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.time.LocalDateTime;

public class SysTemplateDto implements Serializable {
    private long id;

    int pageNum;
    int pageSize;
    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public R validateUpdate(){
        if(this.getId()<0){
            return R.failed("id 不能为空");
        }
        return R.ok(null);
    }










    /**
     * 名称
     */
    private String name;




    /**
     * 模板内容
     */
    private String content;




    /**
     * 分类id
     */
    private int classId;




    /**
     * 分类名称
     */
    private String className;

      // 后缀
    private String fileSuffix;

    public String getFileSuffix() {
        return fileSuffix;
    }

    public void setFileSuffix(String fileSuffix) {
        this.fileSuffix = fileSuffix;
    }

    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    public  String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }

    public int getClassId() {
        return classId;
    }
    public void setClassId(int classId) {
        this.classId = classId;
    }

    public String getClassName() {
        return className;
    }
    public void setClassName(String className) {
        this.className = className;
    }




    /**
     * build
     */
    public static SysTemplateDto build(){
        SysTemplateDto temp = new SysTemplateDto();



        temp.setId(0);

        temp.setName("");

        temp.setContent("");

        temp.setClassId(0);

        temp.setClassName("");


        return temp;
    }

    /**
     * setDefaultValue
     */
    public void  setDefaultValue(SysTemplateDto temp){

        if(this.id<=0){
            temp.setId(0);
        }

        if(StringUtils.isEmpty(this.name)){
            temp.setName("");
        }

        if(StringUtils.isEmpty(this.content)){
            temp.setContent("");
        }


        if(this.classId<=0){
            temp.setClassId(0);
        }

        if(StringUtils.isEmpty(this.className)){
            temp.setClassName("");
        }

    }



    /**
     * dto2entity
     */
    public SysTemplate  dto2entity(){
        var entity=SysTemplate.build();

        if(this.id>0){
            entity.setId(this.getId());
        }

        if(!StringUtils.isEmpty(this.name)){
            entity.setName(this.getName());
        }

        if(!StringUtils.isEmpty(this.content)){
            entity.setContent(this.getContent());
        }

        if(this.classId>0){
            entity.setClassId(this.getClassId());
        }

        if(!StringUtils.isEmpty(this.className)){
            entity.setClassName(this.getClassName());
        }
        if(!StringUtils.isEmpty(this.getFileSuffix())){
            entity.setFileSuffix(this.getFileSuffix());
        }


        return entity;
    }



    public Page<SysTemplate> buildPage(){
        Page<SysTemplate> tempage = new Page<SysTemplate>();
        tempage.setCurrent(this.getPageNum()<=0?0:this.getPageNum());
        tempage.setSize(this.getPageSize()<=0?10:this.getPageSize());
        return tempage;
    }


}